<layout name="bootlayout" />
<script src="__JS__jquery.form.js"></script>
<style>
    .set_div {
        width: 100%;
        border-top: 2px solid #ddd;
        padding: 10px;
    }
</style>
<div style="margin:10px;">
    <div style="width:100%;">
        栏目管理：
    </div>
    <div style="margin:10px 0 0 50px;">
        <table class="table">
            <thead>
                <tr>
                    <th> id</th>
                    <th> 账号</th>
                    <th>昵称</th>
                    <th>注册时间</th>
                    <th> 操作</th>
                </tr>
            </thead>
            <tbody>
            <foreach name="userinfo" item="vo" >    
             <tr>
                            <td>{$vo.id}</td>
                            <td>{$vo.user_id}</td>
                            <td>{$vo.user_show}</td>
                            <td>{$vo.creatdate}</td>
                            <td>
                                <button type="button" class="btn btn-default" data-toggle="modal" data-target="#User" onclick="model_up('{$vo.id}');">
                                    修改
                                </button>
                                <button type="button" class="btn btn-default" data-toggle="modal"  onclick="user_de('{$vo.id}');">
                                    删除
                                </button>
                            </td>
                        </tr>
                     </foreach>   
            </tbody>
        </table>
        <div class="btn-group set_div">
            <button type="button" class="btn btn-default" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#User" onclick="user_add();">
                新增
            </button>
        </div>
        <!--新增用户sart-->
        <div class="modal fade" id="User" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title">新增/修改</h4>
                    </div>
                    <div class="modal-body" style="overflow:hidden;">
                        <form action="/admin/Users/index" method="post" id="model_set">
                            <input type="hidden" id="id" name="id"/>
							<input type="hidden" id="thumb" name="thumb"/>
                            <div style="float:left;width:50%;">
                                <div class="form-group">
                                    <label for="exampleInputEmail1">
                                        昵称：
                                    </label>
                                    <input type="text" class="form-control" id="user_show" name="user_show">
                                </div>
                                <div class="form-group" id="up_user_id" style="display:none;">
                                   
                                </div>
                                <div class="form-group" id="add_user_id">
                                    <label for="exampleInputEmail1">
                                        账号：
                                    </label>
                                    <input type="text" class="form-control" id="user_id" name="user_id">
                                </div>
                                
                                <div class="form-group">
                                    <label for="exampleInputEmail1">
                                       密码：
                                    </label>
                                    <input type="password" class="form-control" id="password" name="password">
                                </div>
                            </div>
                        </form>
                        <div style="width:50%;float:right;">
                                 <!-- 						缩略图上传 -->
						<style>
	                     .upload-img-thumb{width:100%;position: relative;}
	                     .upload-img-thumb1{border:1px solid #eee;border-top:2px solid #eec;-webkit-border-radius: 6px;border-radius: 6px;}
						.upload-img-thumb2{margin: 0 auto; width: 167px; margin-bottom: 20px;}
	                     #img_preview{width: 167px; height: 125px;}
	                     #file_upload{margin:0 auto;}
						</style>
							<div class="upload-img-thumb"></div>
							<div class="upload-img-thumb1">
							<div class="upload-img-thumb2">
								<img  <?php if($data['thumb']){?>src="<?=$data['thumb'] ?>" <?php }else{?> src="__IMG__images.jpg" <?php }?>  id="img_preview">
							</div>
							<div style="width: 100%;">
									<div class="col-lg-6" style="width:100%;">
													<input id="file_upload" name="thumb" type="file" multiple="true">
										<div style="width:90px;margin:0 auto;">
										<a href="javascript:$('#file_upload').uploadify('cancel')" class="button" >删除</a>
										<a href="javascript:$('#file_upload').uploadify('upload')" class="button" style="">上传</a>
										</div>
									</div>
							</div>
							</div>
								<script type="text/javascript">
								    $(function() {
								        $('#file_upload').uploadify({
								       	 'auto'     : false,
								            'swf'      : '/Public/js/uploadify.swf',    //指定上传控件的主体文件
								            'uploader' : '/admin/logining/imgUpload',    //指定服务器端上传处理文件
								            'onUploadSuccess' : function(file, data, response) {
								                $("#img_preview").attr("src",data);
								 	 			$("#thumb").val(data);
								            }
								        });
								    });
								</script>
<!-- 							end 缩略图上传 -->
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">
                            Close
                        </button>
                        <button type="button" class="btn btn-primary" onclick="model_save();" id="model_save" disabled="disabled">
                            保存
                        </button>
                    </div>
                </div>
            </div>
        </div>
        <!--新增用户end-->
       
    </div>
</div>
<script>
	//检查账号是否重复
	$("#user_id").change(function(){
				var user_id=$(this).val();
				$.post("/admin/Users/checkUserid",{user_id:user_id},function(data){
					if(data==0){
						$("#model_save").removeAttr("disabled");
						}else{
							alert("账号已经注册！");
							$("#model_save").attr("disabled","disabled");
							}
					});
				});
});
function model_up(id){
		$("#model_save").removeAttr("disabled");
		$("#user_id").removeAttr("name");
		$.post("/admin/Users/getUser",{id:id},function(data){
			 $("#add_user_id").hide();
			 $("#up_user_id").html("<label for='exampleInputEmail1'> 账号: &nbsp&nbsp&nbsp&nbsp"+data['user_id']+"</label>");
			 $("#up_user_id").show();
				var thumb=data['thumb'];
				$("#user_show").val(data['user_show']);
			    $("#id").val(data['id']);
				$("#thumb").val(data['thumb']);
				  $("#password").val("");
		 	if(!thumb){
	 		 $("#img_preview").attr("src","/Public/images/images.jpg");
		 		}else{
		 		 $("#img_preview").attr("src",thumb);
			 	}
			});
}
function user_add(){
	$("#model_save").attr("disabled","disabled");
	$("#user_id").attr("name","user_id");
    $("#user_show").val("");
    $("#password").val("");
    $("#id").val("");
    $("#user_id").val("");
	 $("#thumb").attr("");
	 $("#img_preview").attr("src","/Public/images/images.jpg");
	 $("#add_user_id").show();
	 $("#up_user_id").hide();
}
function model_save(){
	var pw=  $("#password").val();
	if(pw==""||pw==null){
			alert("密码不能为空 ！");
			return false;
		}
    $("#model_set").submit();
}
//删除用户
function user_de(id){
	if(confirm("确定删除！")){
	  $.post("/admin/Users/deUser",{id:id},function(){
			location.reload();
		  });
		}
}
</script>
